<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户ID" prop="uid">
        <el-input v-model="queryParams.uid" placeholder="请输入用户ID" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table v-loading="loading" :data="recordInfoList">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="uid" />
      <el-table-column label="认证类型" align="center" prop="type" />
      <el-table-column label="认证平台" align="center" prop="platform" />
      <el-table-column label="认证状态" align="center" prop="status" />
      <el-table-column label="认证参数" align="center" prop="paramInfo" />
      <el-table-column label="认证分数" align="center" prop="source" />
      <el-table-column label="返回码" align="center" prop="code" />
      <el-table-column label="返回信息" align="center" prop="message" />
      <el-table-column label="返回结果" align="center" prop="resultInfo">
        <template slot-scope="scope">
          <el-tooltip :content="scope.row.resultInfo" placement="top-start" :disabled="scope.row.resultInfo.length <= 20">
            <div>{{ scope.row.resultInfo.length <= 20 ? scope.row.resultInfo : scope.row.resultInfo.slice(0, 20) + '...'
            }}</div>
          </el-tooltip>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listRecordInfo, getRecordInfo, delRecordInfo, addRecordInfo, updateRecordInfo } from "@/api/member/recordInfo";

export default {
  name: "RecordInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户认证历史表格数据
      recordInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        uid: null,
        type: null,
        configId: null,
        platform: null,
        outOrderNo: null,
        status: null,
        requestParam: null,
        requestResult: null,
        paramInfo: null,
        source: null,
        code: null,
        message: null,
        resultInfo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户认证历史列表 */
    getList() {
      this.loading = true;
      listRecordInfo(this.queryParams).then(response => {
        this.recordInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uid: null,
        type: null,
        configId: null,
        platform: null,
        outOrderNo: null,
        status: null,
        requestParam: null,
        requestResult: null,
        paramInfo: null,
        source: null,
        code: null,
        message: null,
        resultInfo: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户认证历史";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecordInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户认证历史";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecordInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecordInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户认证历史编号为"' + ids + '"的数据项？').then(function () {
        return delRecordInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('member/recordInfo/export', {
        ...this.queryParams
      }, `recordInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
